package calorie.com.calorie.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.SPUtils;

import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.request.ConsuptionRecordRequest;
import calorie.com.calorie.response.ConsumptionRecordResponce;
import retrofit2.Call;
import retrofit2.Response;

public class ConsumptionContact {
    public static class ConsumptionPresent extends BasePresent<IConsuptionView> {
        public void queryConsuptionRecord(Context context,int pageNo){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            ConsuptionRecordRequest request=new ConsuptionRecordRequest(userId,pageNo);
            service.queryConsumptionRecord(request).enqueue(new NetCallBack<ConsumptionRecordResponce>() {
                @Override
                public void onSuccess(Call<ConsumptionRecordResponce> call, Response<ConsumptionRecordResponce> response) {
                    if (getView()!=null){
                        getView().getConsuptionRecord(response);
                    }
                }

                @Override
                public void onFailed() {

                  //  ToastUtils.showLongToast(context,"网络请求异常");


                }
            });
        }
    }

    public interface IConsuptionView extends IBaseView {
        void getConsuptionRecord(Response<ConsumptionRecordResponce> response);
    }
}
